package cn.rxyb.core.date.enums;


import java.util.regex.Pattern;

/**
 * @author YJH
 * @version 1.0
 * @description 时间格式
 * @date 2020/6/20 15:44
 */
public enum FormatDate {

    FORMAT_YEAR("YYYY", "^\\d{4}$"),
    FORMAT_MONTH_LONG("yyyyMM", "^\\d{6}$"),
    FORMAT_MONTH_STR("yyyy-MM", "^\\d{4}\\-\\d{2}$"),
    FORMAT_MONTH_SPRIT("yyyy/MM", "^\\d{4}\\/\\d{2}$"),
    FORMAT_MONTH_CHINESE("yyyy年MM月", "^\\d{4}\\年\\d{2}\\月$"),
    FORMAT_DATE_LONG("yyyyMMdd", "^\\d{8}$"),
    FORMAT_DATE_STR("yyyy-MM-dd", "^\\d{4}\\-\\d{2}\\-\\d{2}$"),
    FORMAT_DATE_SPRIT("yyyy/MM/dd", "^\\d{4}\\/\\d{2}\\/\\d{2}$"),
    FORMAT_DATE_CHINESE("yyyy年MM月dd日", "^\\d{4}\\年\\d{2}\\月\\d{2}\\日$"),
    FORMAT_TIME_LONG("yyyyMMddHHmmss", "^\\d{14}$"),
    FORMAT_TIME_STR("yyyy-MM-dd HH:mm:ss", "^\\d{4}\\-\\d{2}\\-\\d{2}\\ \\d{2}\\:\\d{2}\\:\\d{2}$"),
    FORMAT_TIME_CHINESE("yyyy年MM月dd日 HH:mm:ss", "^\\d{4}\\年\\d{2}\\月\\d{2}\\日 \\d{2}\\:\\d{2}\\:\\d{2}$"),
    FORMAT_TIME_HOUR_MINUTE_SECOND("yyyy年MM月dd日 HH时mm分ss秒", "^\\d{4}\\年\\d{2}\\月\\d{2}\\日 \\d{2}\\时\\d{2}\\分\\d{2}\\秒$"),
    FORMAT_TIME_SPRIT("yyyy/MM/dd HH:mm:ss", "^\\d{4}\\/\\d{2}\\/\\d{2}\\ \\d{2}\\:\\d{2}\\:\\d{2}$"),
    FORMAT_TIME_NORM("HH:mm:ss", "^\\d{2}\\:\\d{2}\\:\\d{2}$"),
    FORMAT_TIME_HOUR("hhmmss", "^\\d{6}$"),
    ;
    private final String value;

    private final String pattern;

    FormatDate(String value, String pattern) {
        this.value = value;
        this.pattern = pattern;
    }

    public String getValue() {
        return this.value;
    }

    public String getPattern() {
        return pattern;
    }

    /**
     * 格式配置
     *
     * @param value
     * @return
     */
    public static FormatDate getValue(String value) {
        FormatDate[] ecs = FormatDate.values();
        for (FormatDate ec : ecs) {
            if (Pattern.matches(ec.pattern, value)) {
                return ec;
            }
        }
        return null;
    }


}
